package com.github.sbb.sherry.primitives.rules;

import com.github.sbb.sherry.common.annotations.NotNull;
import com.github.sbb.sherry.primitives.api.Facts;
import com.github.sbb.sherry.primitives.api.FactsSupplier;
import com.github.sbb.sherry.primitives.api.Fetcher;
import com.github.sbb.sherry.primitives.exception.FetcherException;
import java.util.List;
import java.util.Map;

public class FetcherFactsSupplier implements FactsSupplier {

  @NotNull
  private List<Fetcher> fetchers;

  public FetcherFactsSupplier(@NotNull List<Fetcher> fetchers) {
    this.fetchers = fetchers;
  }

  @Override
  public Facts get(Map<String, Object> params) {
    Facts facts = new Facts();
    for (Fetcher fetcher : fetchers) {
      try {
        facts.add(fetcher.emit(params));
      } catch (FetcherException e) {
      }
    }
    return facts;
  }
}
